package com.wontube.smr.cron;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wontube.core.cron.IJobs;
import com.wontube.smr.bo.sites.youtube.cleanup.CleanupBO;



/**
 * @author yuechao
 *
 * 命令格式 cleanup-video -min_version -10 -min_visit_times 2
 * 
 */
public class CleanupVideoJobs implements IJobs {
	private static final Logger logger = LoggerFactory.getLogger(CleanupVideoJobs.class);
	
	/* 
	 * @see smr.cron.jobs.IJobs#name()
	 */
	@Override
	public String name() {
		return "cleanup-video";
	}

	/* 
	 * @see smr.cron.jobs.IJobs#execute()
	 */
	@Override
	public IJobs execute(String[] args) {
		int minVersion = -10;
		int minVisitTimes = 2;
		for (int i = 0; i < args.length - 1; i++) {
			String arg = args[i];
			if ("-min_version".equals(arg)) {
				minVersion = Integer.parseInt(args[i + 1]);
			} else if ("-min_visit_times".equals(arg)) {
				minVisitTimes = Integer.parseInt(args[i + 1]);
			}
		}
		
		int count = CleanupBO.cleanupVideo(minVersion, minVisitTimes);
		logger.info("deleted {} records", count);
		
		return this;
	}
}
